# Table of IPL-12 Cronbach's Alpha values
cAl12 <- rbind(
  round(psych::alpha(subset(df, select = c(read, speak)))$total[c(1:3, 6)], digits = 2),
  round(psych::alpha(subset(df, select = c(polUnderstanding, polDiscuss)))$total[c(1:3, 6)], digits = 2),
  round(psych::alpha(subset(df, select = c(dinner, contactsInUsCat2)))$total[c(1:3, 6)], digits = 2),
  round(psych::alpha(subset(df, select = c(income, employment3cat)))$total[c(1:3, 6)], digits = 2),
  round(psych::alpha(subset(df, select = c(connectionHc, outsider)))$total[c(1:3, 6)], digits = 2),
  round(psych::alpha(subset(df, select = c(seeDoctor, findJobs)))$total[c(1:3, 6)], digits = 2)
)
cAl12 <- data.frame(cAl12)
cAl12$Dimension <- c("Linguistic", "Political", "Social", "Economic", "Psychological", "Navigational")
cAl12 <- cAl12[,c(5, 1, 4, 2, 3)]
names(cAl12) <- c("Dimension", "Raw Alpha", "Alpha's SE", "Std. Alpha", "Guttman's Lambda 6")

stargazer(cAl12, 
          title = c("Cronabach's Alpha for each dimension of the IPL-12"),
          summary = FALSE,
          rownames = FALSE,
          align = TRUE,
          digits = 2,
          out = c(here::here("Draft/PNAS/draft/tables", "cAl12.tex")))

# Table of IPL-24 Cronbach's Alpha values
cAl24 <- rbind(
  round(psych::alpha(subset(df, select = c(read, speak, write, listen)))$total[c(1:3, 6)], digits = 2),
  round(psych::alpha(subset(df, select = c(polUnderstanding, polDiscuss, polQuiz, polAction)))$total[c(1:3, 6)], digits = 2),
  round(psych::alpha(subset(df, select = c(dinner, contactsInUsCat2, maxOrg, favors)))$total[c(1:3, 6)], digits = 2),
  round(psych::alpha(subset(df, select = c(income, employment3cat, expenses, emplSatisfied)))$total[c(1:3, 6)], digits = 2),
  round(psych::alpha(subset(df, select = c(connectionHc, outsider, isolation, futureHc)))$total[c(1:3, 6)], digits = 2),
  round(psych::alpha(subset(df, select = c(seeDoctor, findJobs, legalProblems, AdDTM)))$total[c(1:3, 6)], digits = 2)
)
cAl24 <- data.frame(cAl24)
cAl24$Dimension <- c("Linguistic", "Political", "Social", "Economic", "Psychological", "Navigational")
cAl24 <- cAl24[,c(5, 1, 4, 2, 3)]
names(cAl24) <- c("Dimension", "Raw Alpha", "Alpha's SE", "Std. Alpha", "Guttman's Lambda 6")

stargazer(cAl24, 
          title = c("Cronabach's Alpha for each dimension of the IPL-24"),
          summary = FALSE,
          rownames = FALSE,
          align = TRUE,
          digits = 2, 
          out = c(here::here("Draft/PNAS/draft/tables", "cAl24.tex")))

# Alpha value for the text

# Cronbach's Alpha for Econ in German sample
psych::alpha(subset(df, survey == "Germany", select = c(income, employment3cat)))$total[2]
round(psych::alpha(subset(df, survey == "Germany", select = c(income, employment3cat, expenses, emplSatisfied)))$total[2], digits = 2)



# Cronbach's Alpha Linguistic
psych::alpha(subset(df, select = c(read, speak)))$total
round(psych::alpha(subset(df, select = c(read, speak, write, listen)))$total[2], digits = 2)

# Cronbach's Alpha Political
psych::alpha(subset(df, select = c(polUnderstanding, polDiscuss)))$total[2]
round(psych::alpha(subset(df, select = c(polUnderstanding, polDiscuss, polQuiz, polAction)))$total[2], digits = 2)

# Cronbach's Alpha Social
psych::alpha(subset(df, select = c(dinner, contactsInUsCat2)))$total[2]
round(psych::alpha(subset(df, select = c(dinner, contactsInUsCat2, maxOrg, favors)))$total[2], digits = 2)

# Cronbach's Alpha Economic
psych::alpha(subset(df, select = c(income, employment3cat)))$total[2]
round(psych::alpha(subset(df, select = c(income, employment3cat, expenses, emplSatisfied)))$total[2], digits = 2)

# Cronbach's Alpha Psychological
psych::alpha(subset(df, select = c(connectionHc, outsider)))$total[2]
round(psych::alpha(subset(df, select = c(connectionHc, outsider, isolation, futureHc)))$total[2], digits = 2)

# Cronbach's Alpha Navigational
psych::alpha(subset(df, select = c(seeDoctor, findJobs)))$total[2]
round(psych::alpha(subset(df, select = c(seeDoctor, findJobs, legalProblems, AdDTM)))$total[2], digits = 2)

